package me.xsomnue.sample.starter.config;

import me.xsomnue.sample.starter.StartServerProperties;
import me.xsomnue.sample.starter.service.StarterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author @叶小夏
 * @since 2019/8/8 0008 9:13
 * - 才需学也,学需静也/非淡泊无以明志，非宁静无以致远
 */
@Configuration
@ConditionalOnClass(StarterService.class)
@EnableConfigurationProperties(StartServerProperties.class)
public class StarterAutoConfigure {

    @Autowired
    private StartServerProperties startServerProperties;


    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "me.tool.sp", value = "enabled", havingValue = "true")
    StarterService starterService() {
        return new StarterService(startServerProperties.getConfig());
    }

}
